package com.sgb.kjwl.view.ui.adapter.packers;

import android.content.Context;
import android.view.View;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemLaborServiceAndEmploymentPublisListBinding;
import com.sgb.kjwl.interfaces.RecyclerClick;
import com.sgb.kjwl.model.entity.packers.LabourServiceAndEmploymentEntity;
import com.sgb.kjwl.utils.PointUtils;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/**
 * @author : younghow
 * @date : 2021/7/814:47
 * @desc :
 */
public class LaborServiceAndEmploymentPublishListAdapter extends BaseRecycleAdapter<LabourServiceAndEmploymentEntity> {

    RecyclerClick<LabourServiceAndEmploymentEntity> mClick;

    public void setClick(RecyclerClick<LabourServiceAndEmploymentEntity> mClick) {
        this.mClick = mClick;
    }

    public LaborServiceAndEmploymentPublishListAdapter(Context context, List<LabourServiceAndEmploymentEntity> data) {
        super(context, R.layout.item_labor_service_and_employment_publis_list, data);
    }

    @Override
    public void convert(ItemViewHolder holder, final LabourServiceAndEmploymentEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ItemLaborServiceAndEmploymentPublisListBinding binding = (ItemLaborServiceAndEmploymentPublisListBinding) holder.getmBinding();
        if ("1".equals(entity.getSalaryType())){
            binding.tvPrice.setText(String.format("%s%s%s",PointUtils.originalPrice(entity.getSalary()),"元/" , (entity.getSalaryUnit() == 1 ? "月" : entity.getSalaryUnit() == 2 ? "季度" : "年")));
        }else {
            binding.tvPrice.setText("2".equals(entity.getSalaryType()) ? "电议" : "面议");
        }

        binding.tvEdit.setOnClickListener(v -> mClick.followClick(entity));
        binding.tvDelete.setOnClickListener(v -> mClick.secondClick(entity));

        if (holder.getIndex_position() == 0){
            binding.ivTag.setVisibility(View.GONE);
        }else {
            binding.ivTag.setVisibility(View.VISIBLE);
        }
    }
}
